import Vue from 'vue'
import VueRouter from 'vue-router'

import routes from './routes'
Vue.use(VueRouter)


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
  scrollBehavior (to , from , savedPosition) {
    if( to.path == "/detail" || to.path == "/More"){
      return {x:0,y:0}	// 让页面出于顶部
    }else{
      return savedPosition	// 让页面处于记录点
    }
  },
})

router.beforeEach((to,from,next)=>{
	if(to.meta.isAuth){ //判断当前路由是否需要进行权限控制
		if(localStorage.getItem('login')){ //权限控制的具体规则
      next()
		}else{
      alert('请先登录！')
			next({name:'Login'})
		}
	}else{
		next()
	}
})

export default router
